<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>compose</title>
</head>

<body>
    <div>打开浏览器控制台查看结果</div>
    <script>
        const compose = (...handlers) =>
            handlers.reduce(
                (f, h) =>
                    (...args) =>
                        f(h(...args))
            );
        const add5 = x => x + 5;
        const multiply = (x, y) => x * y;
        const multiplyAndAdd5 = compose(add5, multiply);
        console.log(multiplyAndAdd5(5, 2));; // 15
    </script>
</body>

</html>